package com.neuedu.aop;


import com.alibaba.fastjson.JSONObject;
import com.neuedu.mq.NeuEmail;
import jakarta.annotation.Resource;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;


@Component
@Aspect
public class AdminAop {

    @Resource
    RabbitTemplate rabbitTemplate;
    @AfterReturning(value = "execution(public * com.neuedu.service.impl.EmployeeServiceImpl.add(..))")
    public void EmpAddAfter (JoinPoint joinPoint) {
        // 获取参数
        final Object[] args = joinPoint.getArgs();
        // 获取信息
        String to = args[5].toString();
        String subject = "云医院系统消息";
        String text = String.format("""
                <h2>%s你好:</h2>
                <p>云医院系统已经为您创建了系统用户,登录名为:%s, 密码为:%s</p>
        """, args[3].toString(), args[4].toString(), args[6].toString());
        // 发送消息
        rabbitTemplate.convertAndSend("handanexchange", "handankey", JSONObject.toJSONString(new NeuEmail(to, subject, text)));
    }
}
